package com.quectel.util.common;

import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class HtmlUtils {
    public static String encode(String html) {
        if (html == null) {
            return null;
        }
        if (JSONUtil.isJson(html)) {
            //可能是json
            try {

                JacksonUtils.parse(html);
                //不抛异常代表真正的json
                return html;
            } catch (Exception e) {
            }
        }
        return cn.hutool.http.HtmlUtil.escape(html);
    }

    public static String decode(String html) {
        if (html == null) {
            return null;
        }

        return cn.hutool.http.HtmlUtil.unescape(html);
    }
}
